# Contributor: Guy Godfroy <guy.godfroy@gugod.fr>
# Maintainer: Guy Godfroy <guy.godfroy@gugod.fr>
pkgname=mimir
pkgver=2.14.0
pkgrel=0
pkgdesc="Horizontally scalable, highly available, multi-tenant, long-term storage for Prometheus"
options="net !check" # cannot get tests to success
url="https://github.com/grafana/mimir"
license="AGPL-3.0-or-later"
# others: needs 64 bits
# riscv64: tests fails
arch="x86_64 aarch64 ppc64le"
makedepends="go bash"
checkdepends="tzdata"
subpackages="$pkgname-openrc"
install="mimir.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/grafana/mimir/archive/refs/tags/mimir-$pkgver.tar.gz
	$pkgname.initd
	$pkgname.confd
	$pkgname.yaml
	"
builddir="$srcdir/$pkgname-$pkgname-$pkgver"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare
	mkdir build
}

build() {
	ldflags="-X github.com/grafana/mimir/pkg/util/version.Version=$pkgver \
		 -X github.com/grafana/mimir/pkg/util/version.BuildUser=$(whoami)@$(hostname) \
		 -X github.com/grafana/mimir/pkg/util/version.BuildDate=$(date -u +"%Y-%m-%dT%H:%M:%SZ")"
	tags="netgo,stringlabels"

	go build -v \
		-o build \
		-ldflags "$ldflags" \
		-tags "$tags" \
		./cmd/...
}

package() {
	mkdir -p "$pkgdir"/etc/$pkgname
	install -Dm0755 build/* -t "$pkgdir"/usr/bin
	install -Dm644 "$srcdir"/$pkgname.yaml "$pkgdir"/etc/mimir/mimir.yaml
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
}

sha512sums="
2673ce48893ac520880d775d78b781775c37ae6928ef14c2245a01f8bdbb0adfad7f6b0eeee4e9318aca6c8ea39a025512834a5f2ea9db3a607407e1192f9124  mimir-2.14.0.tar.gz
7e0121d8d464d202ed8689d9831c2a86740ae4cf0da12f7e723bd90895ff7b3f33a1355dfe6a443e7e5d2a87b159a26b3eef937463a576205bd78dbdb8c01460  mimir.initd
246f0c875828b819bd8f11d49afecd63480626f4d96d95a1431c2d755e356ebe6109b7e0d34262f668c783609f7781cace26a73bfbe660b6626854f0d34fba72  mimir.confd
f4e1ef6f40faaeaa2a46112c023596c94b4d910274b257f5cb19198cfc6c068c3b6fe762b949354547948449a952a5ed1fb93b3cb090e69459cd5b780b4b3d44  mimir.yaml
"
